﻿using Furion.FriendlyException;
using System.ComponentModel;
using System.Reflection;

namespace WeChatV3Pay.Core
{
    public static class EnumExtension
    {
        /// <summary>
        /// 转换为错误信息
        /// </summary>
        public static string ToErrorMessage(this Enum e)
        {
            Type type = e.GetType();
            FieldInfo fi = type.GetField(e.ToString());
            ErrorCodeItemMetadataAttribute attribute = fi.GetCustomAttribute(typeof(ErrorCodeItemMetadataAttribute), true) as ErrorCodeItemMetadataAttribute;
            if (attribute == null)
            {
                return e.ToString();
            }
            return attribute.ErrorMessage;
        }
    }
}